package com.example.androidexample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.androidexample.animation.AnimationActivity;
import com.example.androidexample.base.BaseInfoActivity;
import com.example.androidexample.fingerprint.FingerprintLoginActivity;
import com.example.androidexample.flutter.FlutterPageByFlutterViewActivity;
import com.example.androidexample.interpolater.InterpolaterActivity;
import com.example.androidexample.ndk.NDKExampleActivity;
import com.example.androidexample.ndk.NDKForCppActivity;
import com.example.androidexample.qr.QRActivity;
import com.example.androidexample.searchloading.SearchLoadingActivity;
import com.example.androidexample.settings.SettingsActivity;
import com.example.androidexample.settings.fragments.MainPreferences;
import com.example.androidexample.ui.UIActivity;
import com.example.basic.utils.ProcessUtils;
import com.example.clib.NativeDynamicLibProxy;
import com.example.clib.NativeLibLoader;
import com.example.clib.NativeStaticLibProxy;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;
import java.util.Map;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void openNdk(View view) {
        startActivity(new Intent(this, NDKExampleActivity.class));
    }

    public void openNdk_cpp(View view) {
        startActivity(new Intent(this, NDKForCppActivity.class));
    }

    public void openBaseInfo(View view) {
        startActivity(new Intent(this, BaseInfoActivity.class));
    }

    public void getAllThreadInfo(View view) {
        ProcessUtils.getAllThread();
    }

    public void intoSettings(View view) {
        SettingsActivity.startPage(this, MainPreferences.class,null);
    }
    
    public void intoUI(View view) {
        startActivity(new Intent(this, UIActivity.class));
    }

    public void intoQR(View view) {
        startActivity(new Intent(this, QRActivity.class));
    }

    public void intoAnimation(View view) {
        startActivity(new Intent(this, AnimationActivity.class));
    }

    public void intoInterpolater(View view) {
        startActivity(new Intent(this, InterpolaterActivity.class));
    }

    public void intoSearchLoading(View view) {
        startActivity(new Intent(this, SearchLoadingActivity.class));
    }

    public void intoFlutterByFlutterView(View view) {
        startActivity(new Intent(this, FlutterPageByFlutterViewActivity.class));
    }

    public void intoFingerprint(View view) {
        startActivity(new Intent(this, FingerprintLoginActivity.class));
    }

    public void intoFlutterByFlutterFragment(View view) {
        startActivity(new Intent(this, FlutterPageByFlutterViewActivity.class));
    }

    public void intoFlutterByFlutterActivity(View view) {
        // 方式一、FutterActivity显示的路由名称为"/"，不可设置
//        startActivity(
//                FlutterActivity.createDefaultIntent(this)
//        );

        // 方式二、FutterActivity显示的路由名称可设置，每次都创建一个新的FlutterEngine对象
//        startActivity(
//                FlutterActivity
//                        .withNewEngine()
//                        .initialRoute("/")
//                        .build(this)
//        );

        // 方式三、FutterActivity显示的路由名称可设置，使用缓存好的FlutterEngine对象
        //预热
        FlutterEngine flutterEngine = new FlutterEngine(this);
        flutterEngine.getNavigationChannel().setInitialRoute("/");
        flutterEngine.getDartExecutor().executeDartEntrypoint(
                DartExecutor.DartEntrypoint.createDefault()
        );
        FlutterEngineCache.getInstance().put("my_engine_id", flutterEngine);

        startActivity(
                FlutterActivity
                        .withCachedEngine("my_engine_id")
                        .build(this)
        );
    }
}